var e = require("../@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var t = e(require("../@babel/runtime/regenerator")),
  r = e(require("../@babel/runtime/helpers/asyncToGenerator")),
  n = e(require("./baseURL")),
  a = require("../utils/util");

function u() {
  return s.apply(this, arguments);
}

function s() {
  return (s = (0, r.default)(t.default.mark(function e() {
    var r, u;
    return t.default.wrap(function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.next = 2, new Promise(function (e, t) {
            wx.login({
              success: function (t) {
                wx.setStorageSync("code", t.code), e(t.code);
              },
              fail: function (e) {
                t();
              }
            });
          });

        case 2:
          return r = e.sent, e.next = 5, new Promise(function (e, t) {
            wx.request({
              method: "POST",
              url: "".concat(n.default, "/systems/authorization?code=").concat(r),
              success: function (r) {
                1 === r.data.code ? e(r.data.data) : t();
              },
              fail: function (e) {
                t();
              }
            });
          });

        case 5:
          if (!(u = e.sent)) {
            e.next = 12;
            break;
          }
          return wx.removeStorageSync("Authorization"), (0, a.setToken)(u, (0, a.getUUID)()),
            e.abrupt("return", !0);

        case 12:
          return e.abrupt("return", !1);

        case 13:
        case "end":
          return e.stop();
      }
    }, e);
  }))).apply(this, arguments);
}

function c() {
  return (c = (0, r.default)(t.default.mark(function e() {
    var r, n;
    return t.default.wrap(function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          r = !1, n = 0;

        case 2:
          if (!(n < 3)) {
            e.next = 12;
            break;
          }
          return e.next = 5, u();

        case 5:
          if (!e.sent) {
            e.next = 9;
            break;
          }
          return r = !0, e.abrupt("break", 12);

        case 9:
          n++, e.next = 2;
          break;

        case 12:
          return e.abrupt("return", r);

        case 13:
        case "end":
          return e.stop();
      }
    }, e);
  }))).apply(this, arguments);
}

var i = function () {
  return c.apply(this, arguments);
};

exports.default = i;